package com.teradata.feedProc;

import java.text.MessageFormat;
import java.util.Properties;


/**
 * Read properties file.
 */
public class Config {

	final static Properties defaultProps = new Properties();

	static {
		try {
			//final String propertiesFile = System.getProperty("fileProcPropPath");
			//System.out.println("properties file path is:"+propertiesFile);
			/*final String propertiesFile = "config.properties";
			final File file = new File(propertiesFile);

			if (!file.exists()) {
				System.err.println("Unable to find configuration file:"+propertiesFile);
				System.exit(1);
			}

			final InputStream in = new FileInputStream(file);
			defaultProps.load(in);*/
		    defaultProps.load(Config.class.getClassLoader().getResourceAsStream("config.properties"));
		} catch (Exception e) {
			System.err.println("Failed to load configuration:"+e.getMessage());
			System.out.println(e.getMessage());
			System.exit(1);
		}
	}

	/**
	 * Get property using property key.
	 * @param key
	 * @return string
	 */
	public static String getProperty(final String key) {
		return defaultProps.getProperty(key);
	}

	/**
	 * Get property using property key and arguments.
	 * @param key
	 * @param args
	 * @return string
	 */
	public static String getProperty(final String key, final String... args) {
		MessageFormat mf = new MessageFormat(getProperty(key));
		return mf.format(args, new StringBuffer(), null).toString();
	}
}